package model;

import init.DBManagement;

import java.util.Map;
import java.util.Vector;

import model.beans.AssistantBean;

public class Assistant {
/*
 *	  ACAASIR
	  ASI_TECH_KEY         NUMBER(12) NOT NULL,
       MIN_TECH_KEY         NUMBER(12) NULL,
       TIPO_ASISTENTE       CHAR(1 BYTE) NULL,
       NOMBRE_ASISTENTE     VARCHAR2(50 BYTE) NULL,
       PUESTO_ASISTENTE     VARCHAR2(50 BYTE) NULL,
       STATUS_ASISTENTE     CHAR(1 BYTE) NULL,
       ULTIMA_MOD           DATE NULL,
       
              ASI_TECH_KEY         NUMBER(12) NOT NULL,
       MINUTA_TK         NUMBER(12) NOT NULL,
       ASISTENTE_TK      NUMBER(12)NOT NULL,
       FECHA_ADD           DATE NOT NULL,

 * */
	public static Vector list(int minuta_id){
		Vector assistant_list = new Vector();
		DBManagement db = new DBManagement();
		AssistantBean asistente_bn;		
		int int_rows;
		
		String query = "SELECT ASI_TECH_KEY,                " +
								  " ASISTENTE_TK,                             "  +
								  "  BASUSRB.NOMBRE,                     " +
								  " FECHA_ADD                                   " +
								  " FROM ACAASIR " +
								  "     INNER JOIN BASUSRB                          " +
									"        ON ASISTENTE_TK = BASUSRB.USR_TECH_KEY " +
									"      WHERE MINUTA_TK  = "+minuta_id+"       ";
		db.executeQuery(query);
		int_rows = db.getNumRows();
		
		for(int i=0; i<int_rows; i++){
			asistente_bn = new AssistantBean();
			asistente_bn.setInt_id(Integer.parseInt(db.getItem(i, 0)));
			asistente_bn.setInt_responsable(Integer.parseInt(db.getItem(i, 1)));
			asistente_bn.setStr_responsable(db.getItem(i, 2));		
			asistente_bn.setFecha_add(db.getItem(i, 3));
			
			assistant_list.add(asistente_bn);
		}
		return assistant_list;
		
	}
	
	public static boolean delete( int asistente_id ){		
		String str_delete =
            " delete from ACAASIR "+
            " where  ASI_TECH_KEY = "+asistente_id ;
		DBManagement database = new DBManagement();
        boolean bol_insertStatus = database.executeQuery( str_delete );        
        database = null;
	    return bol_insertStatus;
	}
	
	public static int add(Map map_acuerdo, int int_minuta){
		int int_add;
		int int_responsable =  ((Integer)map_acuerdo.get("int_responsable")).intValue();            
		String str_add =
            " INSERT INTO ACAASIR ( "+
            "        MINUTA_TK, "+
            "        ASISTENTE_TK, "+
            "        FECHA_ADD "+            
            " ) VALUES ( "+
            "        '"+int_minuta+"', "+
            "        '"+int_responsable+"', "+
            "        SYSDATE            "+
            " ) ";
		DBManagement database = new DBManagement();
        boolean bol_insertStatus = database.executeQuery( str_add );
        int_add = bol_insertStatus ? 1 : 0;
        database = null;
	    return int_add;
	}
}
